<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>editor</title>
<script type="text/javascript" src="../../thrid-party/jquery/jquery-1.12.3.min.js"></script>
<script type="text/javascript" src="../js/js_jquery/EWA_ALL.min.2.0.js"></script>
<script type="text/javascript" src="../images/flash/upload/swfupload.js"></script>
<script type="text/javascript" src="../images/flash/upload/swfupload.queue.js"></script>
<script type="text/javascript" src="../images/flash/upload/fileprogress.js"></script>
<script type="text/javascript" src="../images/flash/upload/handlers.js?v=1231"></script>
<script type="text/javascript" src="htmlformat.js"></script>
<script type="text/javascript">
	var swfu;
	var fromName;
	function aaaa() {
		var ref = window.parent.location.href;
		var url = new EWA_UrlClass();
		url.SetUrl(ref);
		var xmlname = url.GetParameter("xmlname");
		var itemname = url.GetParameter("itemname");
		var url1 = new EWA_UrlClass();
		url1.SetUrl(window.location.href);
		var name = url1.GetParameter("name");
		fromName = name;
		var session = url1.GetParameter("jsessionid");

		var settings = {
			flash_url : "../images/flash/upload/swfupload.swf",
			flash9_url : "../images/flash/upload/swfupload_fp9.swf",
			upload_url : parent.EWA.CP + "/EWA_STYLE/cgi-bin/_up_/;jsessionid=" + session + "?EWA_UP_TYPE=SWFUPLOAD&XMLNAME="
				+ xmlname + "&ITEMNAME=" + itemname + "&EWA_UP_GUID=&NAME=" + name,
			file_size_limit : "4 MB",
			file_types : "*.bmp;*.png;*.jpg;*.jpeg;*.gif",
			file_types_description : "*.bmp;*.png;*.jpg;*.jpeg;*.gif",
			file_upload_limit : 10,
			file_queue_limit : 0,
			prevent_swf_caching : false,
			custom_settings : {
				progressTarget : "fsUploadProgress",
				cancelButtonId : "btnCancel"
			},
			debug : false,

			// Button settings
			button_width : "65",
			button_height : "18",
			button_placeholder_id : "IMG",
			button_text : '<span class="theFont">图片</span>',
			button_text_style : ".theFont { font-size: 14px; }",
			button_text_left_padding : 12,
			button_text_top_padding : 3,

			// The event handler functions are defined in handlers.js
			swfupload_preload_handler : preLoad,
			swfupload_load_failed_handler : loadFailed,
			file_queued_handler : fileQueued,
			file_queue_error_handler : fileQueueError,
			file_dialog_complete_handler : fileDialogComplete,
			upload_start_handler : uploadStart,
			upload_progress_handler : uploadProgress,
			upload_error_handler : uploadError,
			upload_success_handler : uploadSuccessDHTML,
			upload_complete_handler : uploadComplete,
			queue_complete_handler : queueComplete
		// Queue plugin event
		};
		swfu = new SWFUpload(settings);
	};
</script>
<style type="text/css">
.but .bt0 {
	overflow: hidden;
	width: 16px;
	height: 16px;
	margin: 3px;
	background-repeat: no-repeat;
	float: left;
	cursor: pointer;
	filter: alpha(opacity =  70);
	opacity: 0.70;
	background-color: #FFF;
}

.bt1 {
	float: left;
	cursor: pointer;
	filter: alpha(opacity =  70);
	opacity: 0.70;
}

.but img {
	position: relative;
}
</style>

</head>
<body style='margin: 0px; overflow: hidden' onload='onload1()'>
	<table width="100%" height=100% border=0 cellspacing=0 cellpadding=0>
		<tr>
			<td colspan=2 height=25 style='border-right: 1px solid #ccc'>
				<div id='buts' class=but onmouseover="mOver(event)" onmousedown="mDown(event)">
					<div class='bt0' id='BOLD'>
						<IMG style="TOP: -304px" src="i.gif">
					</div>
					<div id='ITALIC' class='bt0'>
						<IMG style="TOP: -320px" src="i.gif">
					</div>
					<div id='UNDERLINE' class='bt0'>
						<IMG style="TOP: -336px" src="i.gif">
					</div>
					<div id='InsertOrderedList' class='bt0'>
						<IMG style="TOP: -400px" src="i.gif">
					</div>
					<div id='InsertunOrderedList' class='bt0'>
						<IMG style="TOP: -416px" src="i.gif">
					</div>
					<div id='INDENT' class='bt0'>
						<IMG style="TOP: -448px" src="i.gif">
					</div>

					<div id='Outdent' class='bt0'>
						<IMG style="TOP: -432px" src="i.gif">
					</div>

					<div id='JustifyLEFT' class='bt0'>
						<IMG style="TOP: -464px" src="i.gif">
					</div>
					<div id='JustifyCENTER' class='bt0'>
						<IMG style="TOP: -480px" src="i.gif">
					</div>
					<div id='JustifyRIGHT' class='bt0'>
						<IMG style="TOP: -496px" src="i.gif">
					</div>
					<div id='CreateLink' class='bt0'>
						<IMG style="TOP: -526px" src="i.gif">
					</div>
					<div id='CODE_TXT' tag='html' class='bt0'>
						<IMG style="TOP: -80px" src="i.gif">
					</div>
					<div id='ForeColor' style='width: 48px;' class='bt1'>
						<select onchange='changeForColor(this)'>
							<option value='' style=''></option>
							<option value='black' style='background-color: black'>黑色</option>
							<option value='red' style='background-color: red'>红色</option>
							<option value='blue' style='background-color: blue'>蓝色</option>
							<option value='green' style='background-color: green'>绿色</option>
							<option value='yellow' style='background-color: yellow'>黄色</option>
						</select>
					</div>
				</div>
			</td>
		</tr>
		<tr>
			<td style='border: 1px solid #ccc' colspan=2><iframe id='f1' width=100% height=100% frameborder=0
					src="editor_content.htm?a=1111"></iframe> <iframe id='txt' src='CodeMirror/index.html'
					style='display: none; width: 100%; height: 100%' frameborder=0></iframe></td>
		</tr>
		<tr>
			<td id='tdimgs' style='border: 1px solid #ccc; height: 60px;'>
				<div id=imgs style='width: 100%; height: 58px; overflow: auto; overflow-y: hidden'></div>
			</td>
			<td style='width: 67px; height: 60px;'>
				<div id='IMG' style='width: 67px;'></div>
				<div id='fsUploadProgress' style='font-size: 12px;'></div> <span id=btnCancel></span>
			</td>
		</tr>
	</table>
</body>
<script type="text/javascript">
	var lastFocus;
	function onload1() {
		//$('tdimgs').style.width = (document.body.clientWidth - 60) + 'px';
		//alert($('tdimgs').style.width)
		$X('imgs').innerHTML = "<nobr></nobr>";
		var iframes = window.parent.document.getElementsByTagName('iframe');
		for (var i = 0; i < iframes.length; i++) {
			var o = iframes[i];
			if (o.contentWindow == window) {
				fromObj = o.parentNode.getElementsByTagName('input')[0];
				window.frames[0].document.body.innerHTML = fromObj.value;
				window.frames[0].set_edit_bg();
			}
		}
		var win = window.frames[0];
		var doc = win.document;

		doc.body.onblur = function() {
			fromObj.value = this.document.body.innerHTML;
		}
		aaaa();
		document.getElementById('buts').appendChild(document.getElementById('SWFUpload_0'));
		//fsUploadProgress
		document.getElementById('buts').appendChild(document.getElementById('fsUploadProgress'));
		document.getElementById('fsUploadProgress').style.float = 'right';

	}
	function mOver(evt) {
		var e = evt ? evt : window.event;
		var o = e.srcElement ? e.srcElement : e.target;
		if (o.tagName != 'IMG') {
			return;
		}
		if (lastFocus != null) {
			lastFocus.style.filter = 'alpha(opacity=70)';
			lastFocus.style.opacity = 0.7;
		}
		var o1 = o.parentNode;
		o1.style.filter = 'alpha(opacity=100)';
		o1.style.opacity = 1;
		lastFocus = o1;
	}
	var fullWindow;
	function mDown(evt) {
		var e = evt ? evt : window.event;
		var o = e.srcElement ? e.srcElement : e.target;

		if (o.tagName != 'IMG') {
			return;
		}
		var o1 = o.parentNode;
		if (o1.id == 'FULL') {
			var u = window.frames[0].location.href + '?f=1';
			var width = document.body.offsetWidth;
			var height = document.body.offsetHeight;

			fullWindow = window.parent.EWA.UI.Dialog.OpenWindow(u, 'edit', width, height, false);

		} else if (o1.id == 'CODE_TXT') {
			var tag = o1.getAttribute('tag');
			if (tag == 'html') {
				var html = style_html(window.frames[0].document.body.innerHTML, 4, ' ', 80);
				$X('txt').style.display = '';
				$X('f1').style.display = 'none';
				o1.setAttribute('tag', 'txt');
				if (window.frames[1].editor) {
					window.frames[1].editor.setValue(html);
				} else {
					__VAL__ = html;
					__TYPE__ = 'html';

					window.frames[1].initEditor();
				}
			} else {
				$X('txt').style.display = 'none';
				$X('f1').style.display = '';
				o1.setAttribute('tag', 'html');
				window.frames[0].document.body.innerHTML = window.frames[1].getText();
			}
		} else if (o1.id == 'IMG') {
			insertImg(window);
		} else {
			if (o1.id.indexOf('FormatBlock') == 0) {
				document.execCommand("FormatBlock", false, o1.id.split(',')[1]);
			} else if (o1.id == 'CreateLink') {
				window.frames[0].document.execCommand(o1.id, true, null);
			} else {
				window.frames[0].document.execCommand(o1.id, false, null);
			}
			window.frames[0].document.body.focus();
		}
	}
	function insertImg(win) {
		var retCmd = new window.parent.EWA.UI.Dialog.CMD();
		retCmd.CmdArgus[0] = win;
		retCmd.CmdArgus[1] = "DHTML";
		retCmd.CmdArgus[2] = window.parent.EWA.CP;
		retCmd.CmdArgus[3] = window.parent.EWA.B.IE ? window.frames[0].document.selection.createRange() : null;

		var url = '../cgi-bin/_up_/?EWA_UP_TYPE=IMAGE'
		window.parent.EWA.UI.Dialog.OpenWindow(url, 'loadimg', 420, 300, false, null, retCmd);
	}

	function loadImages(data) {
		var d = eval(data);
		var t = window.parent.$X('UP_IMG_' + fromName);
		for (var i = 0; i < d.length; i++) {
			createImg(d[i]);
			if (t.value.length > 0) {
				t.value += ',';
			}
			t.value += d[i]["UP_UNID"];
		}
	}
	function createImg(d) {
		var img = document.createElement("img");
		var src = (d["ISREAL"] ? "" : EWA.CP + "/") + d["UP_URL"];
		img.src = src;
		img.width = 50;
		img.height = 38;
		img.title = d["UP_NAME"];
		img.style.cursor = 'pointer';
		img.onclick = function() {
			var doc = window.frames[0].document;
			var m = doc.createElement('img');
			m.src = this.src;
			doc.body.appendChild(m);
			m.style.margin = '2px';
		}

		var span = document.createElement("span");
		span.style.marginTop = '2px';
		span.style.border = '1px solid gray';
		span.style.backgroundColor = '#fff';
		span.style.padding = '2px';
		span.appendChild(img);

		$X('imgs').childNodes[0].appendChild(span);
	}
	function changeForColor(o) {
		window.frames[0].document.execCommand('ForeColor', false, o.value);
	}
</script>
<script type="text/javascript" src="../../thrid-party/keymaster-master/keymaster.js"></script>
<script>
	(function() {
		key.filter = function() {
			// 在任何元素上都执行
			return true;
		}
		key('esc', function(event) {
			try {
				parent.$('#butClose').click();
			} catch (e) {
				console.log(e);
			}
			return false; // prevent default && stop propagation
		});
		key('⌘+s,ctrl+s', function(event) {
			fromObj.value = this.document.body.innerHTML;
			try {
				parent.$('#butOk').click();
			} catch (e) {
				console.log(e);
			}
			return false; // prevent default && stop propagation
		});
	})();
</script>
</html>